Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for es module and browser-only environment #539

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

stephen
Copy link

@stephen stephen commented Jan 2, 2023

This PR addresses #284.

I've tested this change using the current create-react-app along with this webpack config:

configure: (webpackConfig) => {
  webpackConfig.resolve.extensions.push(".wasm");
  webpackConfig.experiments = {
    asyncWebAssembly: true,
    topLevelAwait: true,
  };
  webpackConfig.module.rules.forEach((rule) => {
    (rule.oneOf || []).forEach((oneOf) => {
      if (oneOf.type === "asset/resource") {
        oneOf.exclude.push(/\.wasm$/);
      }
    });
  });
  return webpackConfig;
},

This was tricky to figure out. Using the ENVIRONMENT=web flag for the browser
build started causing prepared statements to fail - it would behave as if
no params were passed to db.exec("...", []) as the second arg.

It turns out that the closure compiler was removing the bind() call..

It's not clear to me why, but adding externs that map out the exported
structure fixes the issue.

Some other notes:
- emscripten runs with ADVANCED mode for closure compiler
- closure compiler reuses variables...
- use --closure-args=--debug and --closure-args=--pretty-print for clues
@oleghein oleghein mentioned this pull request Jun 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant